package com.huahang.fashionpress.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huahang.fashionpress.enums.OrderEnum;
import com.huahang.fashionpress.model.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.sql.Date;
import java.util.List;

/**
 * @Author: 阿俊哥
 * @Date: 2019/8/20 15:36
 * @Version 1.0
 *
 * 更新
 * @author : 王翰聪
 * @version : 1.1
 * @since : 2019/08/26
 * 添加了订单增改查
 */
@Repository
public interface OrderMapper extends BaseMapper<Order> {

    /**
     * 添加新订单方法
     * @param orderPrice
     * @param orderStatus 1表示未付款 2表示未发货 3表示待收货 4表示已完成
     * @param orderIsdel 0表示订单未被删除 1表示已删除
     * @param orderDate
     * @param addressID
     * @param userID
     * @return
     */
    @Insert("insert into t_order (order_id, order_price, order_status, order_isdel, order_date, address_id, user_id)" +
            "values (#{orderID}, #{orderPrice}, #{orderStatus}, #{orderIsdel}, #{orderDate}, #{addressID}, #{userID})")
    int insertNewOrder(String orderID, BigDecimal orderPrice, Integer orderStatus, Integer orderIsdel,
                       Date orderDate, Integer addressID, Integer userID);

    /**
     * 修改订单状态
     * @param orderEnum 订单状态枚举
     * @param orderID
     * @param userID
     * @return
     */
    @Update("update t_order set order_status=#{orderStatus} where order_id=#{orderID} and user_id=#{userID}")
    boolean updateOrderStatus(OrderEnum orderEnum, Integer orderID, Integer userID);

    /**
     * 以用户名查找订单
     * @param userID
     * @return
     */
    @Select("select * from t_order where user_id=#{userID}")
    List<Order> selectAllOrderByUserID(Integer userID);

    @Select("select * from t_order where user_id=#{userID} and order_status=#{orderEnum}")
    List<Order> selectAllOrderByUserIDandStatus(Integer userID, OrderEnum orderEnum);

    /**
     * 根据订单号查找订单
     * @param orderDate 订单生成时间
     * @return
     */
    @Select("select * from t_order where order_date=#{orderDate} and user_id=#{userID}")
    Order selectSingleOrderByOrderID(Date orderDate, Integer userID);


}
